﻿using System.Linq;
using Styx;
using Styx.WoWInternals.WoWObjects;

namespace LevelingHelper
{
    class BuffHandler
    {
        private static readonly LocalPlayer Me = StyxWoW.Me;

        public static void CheckForRandomBuff()
        {
            if (CanBuff()) return;
            WoWItem randomBuffItemID = Me.BagItems.FirstOrDefault(item => item.Entry == LHSettings.Instance.BuffItemID);

            if (randomBuffItemID != null)
            {
                Main.Log(string.Format("Attempt to apply Random Buff (Buff ID : {0} / ItemID : {1}",LHSettings.Instance.BuffAuraID, LHSettings.Instance.BuffItemID));
                while (CanBuff()) { randomBuffItemID.Use(); }
            }
        }

        public static bool CanBuff()
        {
            return (IsViable(Me) && !Me.Mounted && !Me.IsOnTransport && !Me.IsResting && !Me.IsDead && !Me.IsGhost && !Me.HasAura(LHSettings.Instance.BuffAuraID));
        }

        public static bool IsViable(WoWObject wowObject)
        {
            return (wowObject != null) && wowObject.IsValid && StyxWoW.IsInGame && StyxWoW.IsInWorld;
        }

    }
}
